<template>
	<view>
		<view>
			<uni-card :title="title" :extra="extra" class="dingdan" @click="chakan()">
				<view>
					<view class="uni-body">日期：{{createDate}}</view>
					<view>金额：{{sumPrice}}</view>
				</view>
			</uni-card>
		</view>
		<view style="display: flex;flex-direction: row;justify-content: space-around;">
			<view></view><text class="text">供货点选择</text>
			<view></view>
		</view>


		<view v-for="item in items">
			<!-- 缺一个弹窗点击返回补货页 -->
			<uni-card :title='item.dhName' class="buhuo" @click="dialogToggle(item.dhName,item.ghId)">
				<text class="uni-body">
					详细地址：{{item.ghSite}}
				</text>
				<view>距离：{{getDistance(item.ghLatitude,item.ghLongitude)}}m</view>
			</uni-card>
		</view>

		<view>
			<!-- 提示窗示例 -->
			<uni-popup ref="alertDialog" type="dialog">
				<uni-popup-dialog :type="msgType" cancelText="关闭" confirmText="同意" title="通知" @confirm="dialogConfirm"
					@close="dialogClose">订单将提交到{{tip}}</uni-popup-dialog>
			</uni-popup>
		</view>
	</view>

</template>

<script>
	import {
		request
	} from '@/network/http.js';
	import {
		methods
	} from 'uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				sumPrice: "",
				extra: "",
				title: "订单号：",
				tip: "",
				type: 'center',
				msgType: 'info',
				messageText: '这是一条成功提示',
				value: '',
				items: [],
				order: {},
				createDate: "",
				longitude:0,
				latitude:0,
				site:""
			}
		},
		onLoad(option) {
			let _this=this
			uni.getLocation({
				type: 'gcj02',
				isHighAccuracy: true,
				success: function(res) {
					_this.longitude = res.longitude;
					_this.latitude = res.latitude;
					console.log('当前位置的经度：' + res.longitude);
					console.log('当前位置的纬度：' + res.latitude);
				}
			})
			request({
				url: `supplier/ssmsuorder/info/${option.orderid}`,
				method: "get",
			}).then(res => {
				this.order = res.data.ssmSuorder
				this.title = this.title + this.order.suId
				this.extra = this.order.state
				this.createDate = this.order.createTime
				this.sumPrice = this.order.price / 100
				console.log(this.order)
			})
			request({
				url: 'supplier/ssmsupplier/list',
				method: 'GET',
				data: {
					page: 1.,
					size: 100,
				}
			}).then(res => {
				this.items = res.data.page.list
				console.log(this.items)
			})
		},
		methods: {
			dialogToggle(type,ghId) {
				this.tip = type
				this.order.ghId=ghId
				this.msgType = type
				this.$refs.alertDialog.open()
			},
			dialogConfirm() {
				console.log('点击确认')
				request({
					url: "supplier/ssmsuorder/update",
					method: "POST",
					data:{
						order:this.order
					}
				}).then(res=>{
					uni.switchTab({
						url:"/pages/buh/buh"
					})
				})
				// this.messageText = `点击确认了 ${this.msgType} 窗口`
			// 	this.$refs.message.open()
			},
			dialogClose() {
				console.log('点击关闭')
			},
			chakan() {
				uni.navigateTo({
					url: "/pages/ddxiangqing/ddxiangqing"
				})
			},
			getDistance( la2, lo2){
				 let La1 = this.latitude * Math.PI / 180.0;
				        let La2 = la2 * Math.PI / 180.0;
				        let La3 = La1 - La2;
				        let Lb3 = this.longitude * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
				        let distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math.sin(Lb3 / 2), 2)));
				        distance = distance * 6378.137;
				        distance = Math.round(distance * 10000) / 10000;
				        return distance;
			}

		}
	}
</script>

<style>
	.buhuo {
		margin-top: 60vh;
	}

	.text {
		text-align: center;
		font-size: 20px;
	}
</style>
